<style lang="scss" scoped>
  .form {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    .el-form-item {
      width: 250px;
    }
  }
</style>
<template>
  <el-dialog :title="title" :visible.sync="addDialogVisible" width="35%">
    <div class="ui-box leave_dialog">
      <el-form :model="userItem" label-width="80px" :rules="formRule" ref="formUser" class="form">
        <el-form-item label="用户名" prop="username">
          <el-input size="mini" v-model="userItem.username"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input size="mini" type="password" show-password v-model="userItem.password"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="addDialogVisible = false" size="mini">取 消</el-button>
        <el-button type="primary" @click="submit" size="mini">确 定</el-button>
      </div>
    </div>
  </el-dialog>
</template>
<script>
  export default {
    name: 'addItem',
    props: {
      userItem: {
        username:'',
        password:''
      }
    },
    data() {
      return {
        formRule: {
          username: [{required: true, message: '请输入名称', trigger: 'blur'}],
          // password: [{trigger: 'blur',required:true}],
          password: [{required: true, message: '密码不能为空', trigger: 'blur'},
            {min: 4, max: 16, message: '密码长度在 4 到 16 个字符', trigger: 'blur'},
            // {pattern:/^(?=.*[0-9])(?=.*[a-zA-Z]).{4,16}$/,message:'请输入正确的密码格式:字母开头+数字'}
            {pattern: /^(?=.*[a-zA-Z]).{4,16}$/, message: '请输入正确的密码格式'}

          ],
          // phone: [{pattern: /^1[3456789]\d{9}$/, message: '请输入正确的电话格式'}],
          // email: [{
          //   pattern: /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,
          //   message: '请输入正确的邮箱格式',
          //   trigger: 'blur'
          // }],
        },
        addDialogVisible: false,
        title: '',
      }
    },
    methods: {
      submit() {
        this.$refs['formUser'].validate((val) => {
          if (val) {
            this.$emit('submit')
          }
        })
      },
      openWindow(value) {
        // console.log('title',value);
        this.title = value;
        this.addDialogVisible = true;
        this.userItem.username=''
        this.userItem.password=''
      }
    }
  }
</script>

